package com.taotao.portal.controller;

import java.io.UnsupportedEncodingException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.portal.pojo.SearchResult;
import com.taotao.portal.service.SearchService;

@Controller
public class SearchController {

	@Autowired
	private SearchService searchService;
	
	@RequestMapping("/search")
	public String search(@RequestParam(value = "q")String queryString,@RequestParam(defaultValue = "1")Integer page,Model model) throws UnsupportedEncodingException {
		
		String query=new String(queryString.getBytes("ISO-8859-1"),"utf-8");
		SearchResult searchResult = searchService.search(query, page);
		model.addAttribute("query", query);
		model.addAttribute("totalPages",searchResult.getPageCount());
		model.addAttribute("itemList", searchResult.getItemList());
		model.addAttribute("page", page);
		return "search";
	}
}
